XML Functions

This topic describes the functions that you can use to handle XML data.

Function Description and Example
XML.parse(str)

Converts an XML string into XML elements.

var xml = XML.parse('<p id="a">b</p>');

In the above example, the value of var is the XML object <p id="a">b</p>. If this object is sent to an output property of the Script dataflow block, the object is converted to a string, and the block property holds a string.

XML.stringify(xmlElement)

Converts XML elements into an XML string

The following example returns the string <p id="a">b</p>.

var xml = XML.parse('<p id="a">b</p>');
					@.a = XML.stringify(xml);
query(str)

Returns the first matching element.

The following example returns <item>ITEM 1</item>.

var xml = XML.parse('<items><item>ITEM 1</item><item>ITEM 2</item></items>');
					xml.query('item');
queryAll(str)

Returns a List of matching elements.

The following example returns <item>ITEM 1</item>, <item>ITEM 2</item>.

var xml = XML.parse('<items><item>ITEM 1</item><item>ITEM 2</item></items>');
						var items = xml.queryAll('item');
					@.a = items.join(', ');
children

Returns a List of all children.

The following example returns B 1,<c>C 1</c>.

var xml = XML.parse('<a><b>B 1<c>C 1</c></b><b>B 2</b></a>');
						var ch = xml.query('b').children;
					return ch.join(',');
elements

Returns a list of children elements.

The following example returns <c>C 1</c>.

var xml = XML.parse('<a><b>B 1<c>C 1</c></b><b>B 2</b></a>');
						var el = xml.query('b').elements;
					return el.join(',');
name

Returns the name of an element.

The following example returns a.

var xml = XML.parse('<a b="1">A</a>');
					return xml.name;
data

Returns the data of an element, when the element is a data node. The text function is strongly recommended instead of the data function.

The following example returns A.

var xml = XML.parse('<a b="1">A</a>');
					return xml.children[0].data;
text

Returns the text of an element. Checks whether the node is a data node or has a data node as a child.

The following example returns A.

var xml = XML.parse('<a b="1">A</a>');
					return xml.text;
getAttribute(str)

Returns an attribute value.

The following example returns 1.

var xml = XML.parse('<items><item att="1">A</item></items>');
						var item = xml.query('item');
						var att = item.getAttribute('att');
					return att;
remove